import os
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LogisticRegression

all_feature_columns = ["time", "click_times", "creative_id", "industry",
                       "advertiser_id","product_category","product_id",
                       "ad_id"]

feature_column = ["time", "click_times", "industry",
                       "advertiser_id","product_category","product_id",
                       ]

target_columns = ["age", "gender"]

train_dir = "/home/datanfs/macong_data/tencent_data/train_preliminary/click_uid_ad.csv"

def train():
    target_column = target_columns[1]
    print("### 最基础的LR,预测目标是性别，二分类 ###")
    print("### 模型基本信息")
    print("feature:", feature_column)
    print("label:", target_column)
    print("max_iter:", 1000)
    print("n_jobs:", -1)
    print("k_fold:", 5)
    train_df = pd.read_csv(train_dir)
    train_df = train_df.fillna(0)
    alg = LogisticRegression(random_state=1, max_iter=1000, n_jobs=1)
    kf = KFold(n_splits=5, shuffle=True, random_state=1)
    scores = cross_val_score(alg, train_df[feature_column], train_df[target_column], cv=kf)
    print(scores.mean())

def unit_test():
    print("### processing unit test ###")
    train()


if __name__ == '__main__':
    unit_test()